package com.dehui.traders.ui.home;

import android.content.Context;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.text.TextPaint;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dehui.traders.R;
import com.dehui.traders.bean.IndexInfo;
import com.dehui.traders.utils.BaseRecyclerAdapter;
import com.dehui.traders.utils.SmartViewHolder;

import java.util.Collection;
import java.util.List;

import me.goldze.mvvmhabit.utils.Utils;

/**
 * Created by hqq on 18.4.18.
 */

public class HomeDataAdapter extends BaseRecyclerAdapter<IndexInfo>{

    private Context context;
    private int selectPos = 1;

    public HomeDataAdapter(Context context, Collection<IndexInfo> collection, int layoutId, AdapterView.OnItemClickListener listener) {
        super(collection, layoutId,listener);
        this.context=context;
    }

    @Override
    protected void onBindViewHolder(SmartViewHolder holder, IndexInfo model, int position) {
        TextView tvTitle = holder.findViewById(R.id.tv_title);
        LinearLayout llContainer = holder.findViewById(R.id.ll_container);
        TextView tvName = holder.findViewById(R.id.tv_name);
        TextView tvIndex = holder.findViewById(R.id.tv_index);
        TextView tvChange = holder.findViewById(R.id.tv_change);
        int widthPixels = Utils.getScreen(context).widthPixels;
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) llContainer.getLayoutParams();
        lp.width = widthPixels / 3;
        llContainer.setLayoutParams(lp);

        tvName.setText(model.name);
        tvTitle.setText(model.close == 0 ? String.valueOf(model.preclose) : String.valueOf(model.close));
        double cha = model.close - model.open;
        if (cha < 0){
            tvTitle.setTextColor(ContextCompat.getColor(context,R.color.green));
        }else{
            tvTitle.setTextColor(ContextCompat.getColor(context,R.color.red));
        }

        tvIndex.setText(Utils.doubleToString(cha));
        tvChange.setText(model.change + "%");


        TextPaint tp = tvTitle.getPaint();
        tp.setFakeBoldText(true);
    }


    public void setSelectPos(int selectPos) {
        this.selectPos = selectPos;
        this.notifyDataSetChanged();
    }



}
